const expressSession = require('express-session')
const redis = require('redis')
const RedisStore = require('connect-redis')(expressSession)
const redisConfig = {
  host: '127.0.0.1',
  port: '16320',
  ttl: 1000 * 60 * 5,
  password: 'u6^8LM*Zme7!Yl4!'
}
const redisClient = redis.createClient(redisConfig.port, redisConfig.host)
redisClient.auth(redisConfig.password, function () {
  console.log("连接成功")
  redisClient.on('ready', res => {
    console.log('redis启动成功')
  })
  redisClient.on('connect', () => {
    console.log('redis connect success')
  })

  redisClient.on('error', err => {
    console.log('redis启动失败', err)
  })
})
const session = {
  store: new RedisStore({ client: redisClient }),
  secret: 'password',
  resave: false,
  saveUninitialized: false,
  cookie: {
    maxAge: 1000 * 60 * 5 // default session expiration is set to 1 hour
  }
}
module.exports = {
  version: '1.0',
  API_VERSION: 'v1',
  saltTime: 6,
  sqldb: {
    db: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'koa_react_vue',
    username: 'root',
    password: 'fwq123',
    timezone: '+08:00' //for writing to database
  },
  redisConfig,
  session,
  initPort: 8085,
  default_avatar: '/default/img/avatar.jpeg',
  port: 8086, // 生产环境运行端口号
  DF_ARTICLE_TAG_IMG: `/default/img/default_article_tag.png`, // 文章默认的标签
  DF_ICON: `/default/img/default_icon.png`, // 默认所有图标
  ENCRYPT_KEY: 'kite',
  DF_ARTICLE_TAG_IMG: `/default/img/default_article_tag.png`, // 文章默认的标签
  DF_ICON: `/default/img/default_icon.png`, // 默认所有图标
  PUBLIC: {},
  USER: {
    dfUserAvatarNoReviewId: 'dfUserAvatarNoReviewId' // 用户头像免审核
  },
  USER_ROLE: {
    dfId: 'ordinary_role_100000', // 用户默认角色id
    dfLegalizeId: 'commission_100000', // 定制角色，认证作者ID
    dfManagementTeam: 'management_team'
  },
  USER_AUTHORITY: {
    dfNoReviewArticleId: 'no_review_article', // 发布文章无需审核的权限id
    dfNoReviewArticleCommentId: 'no_review_comment', // 无需审核评论的权限id
    dfNoReviewDynamicId: 'dfNoReviewDynamicId', // 无需审核动态的权限id
    dfNoReviewDynamicCommentId: 'dfNoReviewDynamicCommentId' // 无需审核动态评论的权限id
  },
  ARTICLE_TAG: {
    dfOfficialExclusive: 'dfOfficialExclusive' // 默认只能由官方使用的文章标签
  },
  DYNAMIC: {
    dfOfficialTopic: 'dfOfficialTopic', // 默认只能由官方使用的动态话题
    dfTreeHole: 'dfTreeHole' // 树洞话题
  },
  ARTICLE_BLOG: {
    dfNoReviewArticleBlogId: 'dfNoReviewArticleBlogId' // 发布个人专栏无需审核的权限id
  },
  BOOK: {
    dfNoReviewBookId: 'dfNoReviewBookId', // 发布小书章节无需审核,
    dfNoReviewBookCommentId: 'dfNoReviewBookCommentId' // 发布小书章节评论无需审核
  },
  BOOKS: {
    dfNoReviewBooksId: 'dfNoReviewBooksId', // 发布小书无需审核,
    dfNoReviewBooksCommentId: 'dfNoReviewBooksCommentId' // 发布小书评论无需审核
  },
  SUPER_ROLE_ID: '1000000', // 排除超管，超管无视所有，拥有最高权限 role = 1000000 为超管
  default_avatar: `/default/img/avatar.jpeg`, // 所有使用的默认头像
  secretOrKey: 'admin-token', // jwtFromRequest token
}